package com.damieoa.damieoa.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.damieoa.damieoa.dao.LoginMapper;
import com.damieoa.damieoa.pojo.Login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.function.Consumer;


@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    //登录验证
    @Override
    public Login login(Login login) {
        if ((login.getUser_name() != null) && (login.getPass_word() != null)){
            Consumer<QueryWrapper<Login>> loginConsumer = new Consumer<QueryWrapper<Login>>() {
                @Override
                public void accept(QueryWrapper queryWrapper) {
                    queryWrapper.eq("pass_word", login.getPass_word());
                }
            };
            QueryWrapper<Login> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("user_name", login.getUser_name()).and(loginConsumer);
            Login user = loginMapper.selectOne(queryWrapper);
            return user;
        }
        return null;
    }

}
